<?php
	$logfiles = array( 
			"/var/log/auth.log" => "Auth",
			"/var/log/apt" => "Pakethanterare",
			"/var/log/mail.log" => "Mailserver",
			"/var/log/mysql.log" => "MySQL",
			"/var/log/syslog" => "Systemlog",
			"/var/log/samba/log.nmbd" => "Windows namnservice",
			"/var/log/samba/log.smbd" => "Windows resursdelning",
			"/var/log/apache2" => "Webserver Apache2",
			"/var/log/thttpd.log" => "Webserver admingränsnitt"
		);


	$logfile = false;
	if( isset($_GET['f']) ) {
		$file = $_GET['f'];
		if( isset($logfiles[$file]) ) {
			$logfile = $file;
		}
	}

	$logstr = htmlentities(file_get_contents($logfile));
	//$logarr = explode("\n", $logstr);

/////////////////////////////////
	

	if( $logfile === false ) {
		html_start();
		echo '<table>';
		foreach( $logfiles AS $path => $name ) {
			echo '<tr><td style="padding-right:1em"><a href="main.php?s=log&amp;f='.$path.'">'.$name.'</a></td><td><a style="color:#00f;font-size:80%" href="main.php?s=log&amp;f='.$path.'">'.$path.'</a></td>';
		}
		echo '</table><br>';
		html_end();
	}
	else if ( isset($_GET['get']) ) {
		echo "Content-type: application/text\n";
		echo "Content-Disposition: attachment; filename=".basename($logfile)."\n";
		echo "\n";
		echo $logstr;
	}
	else {
		html_start();
		/*foreach( $logarr AS $line ) {
			$parts = explode(" ", $line);
			$parts[0] = '<i>'.$parts[0];
			$parts[2] = $parts[2].'</i>';
			unset($parts[3]);
			$parts[4] = '<b>'.$parts[4].'</b>';
			$line =	 implode(" ", $parts);
			echo '<p style="font-size: 80%;">';
			echo $line;
			echo '</p>';
		}*/
		echo '<a style="font-size:80%;color:#00f" href="main.php?s=log&amp;f='.$logfile.'&amp;get=1">Hämta som fil</a><br><br>';
		echo nl2br($logstr);
		echo '<br>';
		html_end();
	}

?>
